﻿using System.Windows;
using System.Windows.Controls;

namespace WpfAdvControls.StatusPanel
{
    /// <summary>
    ///     Interaction logic for ActivityStatusBox.xaml
    /// </summary>
    public partial class ActivityStatusBox : UserControl
    {
        // Using a DependencyProperty as the backing store for ActivityStatus.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ActivityStatusProperty =
            DependencyProperty.Register("ActivityStatus", typeof (string), typeof (ActivityStatusBox),
                new UIPropertyMetadata("NA", OnActivityStatusChanged));

        public ActivityStatusBox()
        {
            InitializeComponent();
        }


        public string ActivityStatus
        {
            get { return (string) GetValue(ActivityStatusProperty); }
            set { SetValue(ActivityStatusProperty, value); }
        }

        private static void OnActivityStatusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var statusString = e.NewValue as string;
            if (statusString == null) return;
            var box = d as ActivityStatusBox;
            if (box == null) return;
            box.UpdateView(statusString);
        }

        private void UpdateView(string status)
        {
            switch (status)
            {
                case "NA":
                    pathPic.Style = BoxGrid.Resources["RunArrow"] as Style;
                    break;
                case "Sheduled":
                    pathPic.Style = BoxGrid.Resources["CogweelRollingPath"] as Style;
                    break;
                case "Executing":
                    pathPic.Style = BoxGrid.Resources["CogweelRollingPath"] as Style;
                    break;
                case "Closed":
                    pathPic.Style = BoxGrid.Resources["Checked"] as Style;
                    break;
                //    case "Warning":
                //        pathPic.Style = BoxGrid.Resources.FindName("CogweelRollingPath") as Style;
                //        break;
                //    case "Error":
                //        pathPic.Style = BoxGrid.Resources.FindName("CogweelRollingPath") as Style;
                //        break;
            }
        }
    }
}